<template>
  <div class="hoWord-list-content">
    <Navbar title="民生事件" :fooBack="true" @back="goback"/>
    <div class="content">
      <p class="title">{{hotWord}}-{{relateWord}}</p>

      <div class="num-wrap flex-between">
        <div class="left flex items-center">
          <img src="@/assets/event/icon-tousu.png" alt="">
          <div>
            <p class="name">投诉数量</p>
            <div class="flex items-end">
              <p class="count"><span>{{eventNum}}</span>件</p>
              <p class="huanbi">
                <span>环比</span>
                <span class="icon icon-huan-up" v-if="eventChainRate>0"></span>
                <span class="icon icon-huan-down" v-else></span>
                <span class="num">{{Math.abs(eventChainRate)}}%</span>
              </p>
            </div>
          </div>
        </div>
        <div class="right flex items-center">
          <van-circle 
            v-model:current-rate="eventRate" 
            :rate="eventRate" 
            :speed="100" 
            :stroke-width="120" 
            :stroke-linecap="'butt'" 
            :layer-color="'rgba(255,255,255,0.3)'" 
            :color="{ '0%': '#fff', '100%': '#fff'}"/>
            <div>
              <p>占比</p>
              <p>{{eventRate}}%</p>
            </div>
        </div>
      </div>

      <QuestionItem :list="questionList"></QuestionItem>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { computed, ref, reactive, toRefs, watch, onActivated, onMounted } from 'vue'
import Navbar from '@/components/Navbar/index.vue'
import { useRouter, useRoute } from 'vue-router'
import EventServe from '@/api/event'
import Cookies from 'js-cookie'
import QuestionItem from "./components/QuestionItem.vue"

defineOptions({
  name: 'HotWordList'
})

const route = useRoute()
const router = useRouter()
const hotWord = route.query.hotWord   //热点词汇
const relateWord = route.query.words   //共现词汇

const eventNum = ref(0)
const eventChainRate = ref(0)  //环比
const eventRate = ref(0)  //占比

// 获取共现词汇出现事件
const questionList = ref([])
const getData = () => {
  EventServe.getRelationWordsFloat({
    time: route.query.time, 
    type: route.query.type,
    word: hotWord,
    relationWord: relateWord
  }).then(res=>{
    questionList.value = res.data.eventList
    eventNum.value = res.data.eventNum
    eventChainRate.value = res.data.eventChainRate
    eventRate.value = res.data.eventRate
  })
}

onMounted(()=>{
  getData()
})

const goback = () => {
  Cookies.set('event_type', '1')
  router.back()
}

</script>

<script lang="ts">

</script>

<style lang="less" scoped>
.hoWord-list-content{
  color: #FFFFFF;
  font-size: 14px;

  .content{
    padding: 16px 12px 100px;
    overflow: auto;
    height: 100vh;
    overflow-y: scroll;
    box-sizing: border-box;
  }
  .title{
    color: #0E0D16;
    font-weight: bold;
    font-size: 15px;
    padding-bottom: 12px;
    line-height: 22px;
  }
  .num-wrap{
    // background: #FF6211;
    background: linear-gradient(to left, #FF7629, #FF9929);
    border-radius: 5px;
    margin-bottom: 12px;
    padding: 10px 12px;
    height: 50px;
    .left{
      img{
        width: 45px;
        height: 45px;
        margin-right: 14px;
      }
      .name{
        margin-bottom: 6px;
      }
      .huanbi{
        font-size: 11px;
        padding-left: 14px;
        .num{
          font-size: 14px;
        }
        .icon{
          margin-left: 3px;
        }
      }
      .count{
        color: #FFFFFF;
        font-size: 11px;
        span{
          font-family: DINPro;
          font-weight: bold;
          font-size: 18px;
          margin-right: 2px;
        }
      }
    }
    .right{
      border-left: 2px solid #FFFFFF4C;
      flex-shrink: 0;
      p{
        line-height: 20px;
      }
    }
    .van-circle{
      width: 43px;
      height: 43px;
      margin: 0 7px 0 15px;
    }
    .icon-huan-up::before, .icon-huan-down::before{
      color: #fff;
    }
  }
}
</style>
